#
# Created by Administrator on 2021/7/28 AT 16:33.
#
from typing import List
from collections import defaultdict


class MagicDictionary:

    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.MD = defaultdict(list)

    def buildDict(self, dictionary: List[str]) -> None:
        for x in dictionary:
            self.MD[len(x)].append(x)

    def search(self, searchWord: str) -> bool:
        for record in self.MD[len(searchWord)]:
            if sum(a != b for a, b in zip(record, searchWord)) == 1:
                return True
        return False


# Your MagicDictionary object will be instantiated and called as such:
# obj = MagicDictionary()
# obj.buildDict(dictionary)
# param_2 = obj.search(searchWord)


if __name__ == '__main__':
    obj = MagicDictionary()
    obj.buildDict(["hello", "leetcode"])
    print(obj.search("hello"))
    print(obj.search("hhllo"))
    print(obj.search("hell"))
    print(obj.search("leetcoded"))
